#include "shader.h"
#include "utils/util.h"
namespace Sivin {
  Shader::Shader(std::string vertexShaderPath, std::string fragmentShaderPath) {
    mVertexShaderSource = SnUtil::readShaderFromPath(vertexShaderPath);
    mFragmentShaderSource = SnUtil::readShaderFromPath(fragmentShaderPath);
  }

  Shader::~Shader() {
  }

  bool Shader::init() {
    if (mInit) {
      return true;
    }
    id = SnUtil::createShaderProgram(mVertexShaderSource.c_str(), mFragmentShaderSource.c_str());
    if (id == 0) {
      mInit = true;
      return false;
    }
    return true;
  }

  void Shader::start() {
    glUseProgram(id);
  }

  void Shader::end() {
    glUseProgram(0);
  }

  void Shader::destruct() {
    if (mInit) {
      glDeleteProgram(id);
    }
    mInit = false;
  }


}// namespace Sivin